(function(vc, vm) {
    vc.extends({
        data: {
            addChainProductInfo: {
                productId: '',
                catalogId: '',
                prodName: '',
                prodDesc: '',
                unitName: '',
                sort: '',
                content: '',
                states: [],
                state: '',
                coverPhoto: '',
                carouselFigurePhotos: [],
                chainProductValueDtos: [],
                productSpecs: [],
                areaCode: '',
                csId: '',
                shopId: '',
                groupId: ''

            },
            chainProductDetail: {},
            productPriceRules: []
        },
        _initMethod: function() {},
        _initEvent: function() {
            vc.on('addChainSupplierProduct', 'openAddChainSupplierProductModal', function(_params) {
                $that.refreshAddChainSupplierProduct();
                $('#addChainSupplierProduct').modal('show');
                vc.copyObject(_params, $that.addChainProductInfo);
                console.log($that.addChainProductInfo);
                $that.addChainProductInfo.shopId = vc.getCurrentCommunity().shopId;
                $that.addChainProductInfo.groupId = $that.chainSupplierInfo.conditions.catalogId;
                $that._listProductPriceRules();
                $that._listProductDetail();
            });
        },
        methods: {
            _listProductDetail: function() {
                let param = {
                    params: {
                        productId: $that.addChainProductInfo.productId,
                        page: 1,
                        row: 50,
                        csId: $that.chainSupplierInfo.conditions.csId
                    }
                };
                //发送get请求
                vc.http.apiGet('chainProduct.queryProductDeatil',
                    param,
                    function(json, res) {
                        let _json = JSON.parse(json);
                        $that.chainProductDetail = _json.data;
                        console.log($that.chainProductDetail.specs.options[0].id);
                        $that.skuId = $that.chainProductDetail.specs.options[0].id;
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },

            _listProductPriceRules: function() {
                var param = {
                    params: {
                        page: 1,
                        row: 100,
                        shopId: vc.getCurrentCommunity().shopId
                    }
                };
                //发送get请求
                vc.http.apiGet('/productPriceRule.listProductPriceRule',
                    param,
                    function(json, res) {
                        let _json = JSON.parse(json);
                        $that.productPriceRules = _json.data;
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },

            saveSupplierOrder: function() {
                vc.http.apiPost(
                    '/chainInoutOrder.saveChainInoutOrder',
                    JSON.stringify($that.addChainProductInfo), {
                        emulateJSON: true
                    },
                    function(json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#addChainSupplierProduct').modal('hide');
                            $that.refreshAddChainSupplierProduct();
                            vc.toast("采购成功");
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            refreshAddChainSupplierProduct: function() {
                $that.addChainProductInfo = {
                    productId: '',
                    catalogId: '',
                    prodName: '',
                    prodDesc: '',
                    unitName: '',
                    sort: '',
                    content: '',
                    states: [],
                    state: '',
                    coverPhoto: '',
                    carouselFigurePhotos: [],
                    chainProductValueDtos: [],
                    productSpecs: [],
                    areaCode: '',
                    csId: '',
                    shopId: '',
                    groupId: ''
                }
            }
        }
    });
})(window.vc, window.$that);